import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/4/19 13:08
 */

public class Solution {
    public int minCostClimbingStairs(int[] cost) {
        int n = cost.length;
        int[] dp = new int[n];
        // 初始化dp数组的最后一个元素，即到达最后一阶楼梯的花费
        dp[n - 1] = cost[n - 1];
        // 初始化dp数组的倒数第二个元素，即到达倒数第二阶楼梯的花费
        dp[n - 2] = cost[n - 2];
        for (int i = n - 3; i >= 0; i--) {
            // 到达当前阶楼梯的最小花费等于到达下一阶或下两阶楼梯的最小花费加上当前阶的花费
            dp[i] = Math.min(dp[i + 1],dp[i + 2]) + cost[i];
        }
        return Math.min(dp[0],dp[1]);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int len = in.nextInt();
            int[] cost = new int[len];
            for (int i = 0; i < len; i++) {
                cost[i] = in.nextInt();
            }
            Solution solution = new Solution();
            System.out.println(solution.minCostClimbingStairs(cost));
        }
    }
}